package com.itheima.Day11;

public class Sellticket implements Runnable{
    //确认次数
    private int cishu = 100;
    //加锁
    private  Object ob = new Object();


    @Override
    public void run() {
        //开始循环
        while (true){
            //进入后开始上锁
            synchronized (ob){
            if (cishu<=0){
                return;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            cishu--;
            System.out.println(Thread.currentThread().getName()+"现在正在卖第"+cishu+"张票");
            }
        }
    }
}
